Working with parameter fields

Crystal parameters and stored procedure parameters and are both set through the ParameterFieldDefinition Object. The following sample code passes four parameters to a report. The Main Report and the Subreport each have a Stored Procedure and a Crystal Parameter.

This code can go in the General Declarations Section.

Private Sub Command1_Click() 
Dim CRXParamDefs As CRAXDRT.ParameterFieldDefinitions 
Dim CRXParamDef As CRAXDRT.ParameterFieldDefinition 
Dim CRXSubreport As CRAXDRT.Report 
Set CRXParamDefs = CRXReport.ParameterFields 

This code cycles through the ParameterFieldDefinitions collection in the main report.

For Each CRXParamDef In CRXParamDefs 
With CRXParamDef 
Select Case .ParameterFieldName 

It finds and sets the appropriate Crystal parameter.

Case "MainParam" 
.SetCurrentValue "Main Report Parameter" 

Now it finds and sets the appropriate stored procedure parameter.

Case "[CustomerID]" 
.SetCurrentValue "Alfki" 
End Select 
End With 
Next 

It opens the appropriate subreport.

Set CRXSubreport = CRXReport.OpenSubreport("sub1") 
Set CRXParamDefs = CRXSubreport.ParameterFields 

It cycles through the ParameterFieldDefinitions collection for the subreport.

For Each CRXParamDef In CRXParamDefs 
With CRXParamDef 
MsgBox .ParameterFieldName 
Select Case .ParameterFieldName 

It finds and sets the appropriate Crystal parameter for the subreport.

Case "SubParam" 
.SetCurrentValue "Subreport Parameter" 

Now it finds and sets the appropriate stored procedure parameter for the subreport.

Case "[CustomerID]" 
.SetCurrentValue "Anton" 
End Select 
End With 
Next 

Finally, it disables parameter prompting so the user won't be prompted for a value.

CRXReport.EnableParameterPrompting = False 
CRViewer1.ReportSource = CRXReport 
CRViewer1.ViewReport 
End Sub


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com